package DataModel;

import java.sql.*;

import javax.swing.JOptionPane;

public class DataModel {
        
   Connection con;
   Statement st;
   ResultSet rs;
   ResultSet rs1;
   
    public DataModel() {
    	connect();
    }
    
    public void connect(){
    Connection con = null;
    try {
    	String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    	Class.forName(driver);
    		
    	String db = "jdbc:odbc:data";
    	con = DriverManager.getConnection(db);
    		
    	st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    	String sql = "select * from Table1";
    	rs = st.executeQuery(sql);
    	
    	 Connection con1 = null;
    	    try {
    	      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    	      con = DriverManager.getConnection("jdbc:odbc:HY_ACCESS");

    	// Creating a database table
    	      Statement sta = con.createStatement(); 
    	      int count = sta.executeUpdate(
    	        "CREATE TABLE HY_Address (ID INT, StreetName VARCHAR(20),"
    	        + " City VARCHAR(20))");
    	      System.out.println("Table created.");
    	      sta.close();
    	      
    	      	String sql1 = "select * from HY_ACCESS";
    	    	rs1 = st.executeQuery(sql);
    	    	
    	      	rs1.updateString("Fname", "firstName");
    			rs1.updateString("Lname", "lastName");
    			rs1.updateString("age", "age");
    			rs1.updateRow();
    			
    			JOptionPane.showMessageDialog(null, rs1.getString("Fname"));

    	      con.close();        
    	    } catch (Exception e) {
    	      System.err.println("Exception: "+e.getMessage());
    	    }
    	
    	
    		
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    }
    
   
    public static void main(String[] args) {
        new DataModel();
        
       new GUI();
    }
}
